<?php
require_once "classdb.php";

// class user **********************************************************************************
class user extends db{
	private $table="user";
	public $id=NULL;
	public $username=NULL;
	public $password=NULL;
	public $hoten=NULL;
	public $diachi=NULL;
	public $dienthoai=NULL;
	public $email=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $idgroup=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_username($username) { $this->username=$username; }
	function dt_set_password($password) { $this->password=$password; }
	function dt_set_hoten($hoten) { $this->hoten=$hoten; }
	function dt_set_diachi($diachi) { $this->diachi=$diachi; }
	function dt_set_dienthoai($dienthoai) { $this->dienthoai=$dienthoai; }
	function dt_set_email($email) { $this->email=$email; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_idgroup($idgroup) { $this->idgroup=$idgroup; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
    
	function get_by_username($username) {
		$query = "SELECT * FROM ".$this->table." WHERE username='$username'";
		return $this->get_data_db($query);
	}
	
	function get_by_ngay_admin() {
		$query = "SELECT * FROM ".$this->table." WHERE idgroup<>-1 order by ngay DESC";
		return $this->get_list_data_db($query);
	}
}

// class tin_theloai **********************************************************************************
class quantri extends db{
	function rootlist($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"tin_root", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function tin_theloailist($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"tin_theloai", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function tin_loailist($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"tin_loai", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function tin_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"tin", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function lienhe_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"lienhe", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function tintuc_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"tintuc", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function field_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"field", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function quangcao_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"quangcao", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function lienketweb_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"lienketweb", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function thongtinkhac_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"thongtinkhac", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function dichvu_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"dichvu", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	
	function sanpham_loai_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"sanpham_loai", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function sanpham_loailop_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"sanpham_loailop", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function sanpham_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"sanpham", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function donhang_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_order($pageNum,$pageSize,$totalRows,"donhang", -1, -1, "and tennguoinhan like '%$tukhoa%'",' order by datratien desc');
	}
	function users_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_order($pageNum,$pageSize,$totalRows,"users", -1, -1, "and (email like '%$tukhoa%' or hoten like '%$tukhoa%')",' order by id desc');
	}
	
	function chamsocda_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"chamsocda", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function quitrinhtrimun_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"quitrinhtrimun", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function loaicauhoi_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"loaicauhoi", -1, -1, "and ten_vi like '%$tukhoa%'",'');
	}
	function tuvan_list($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='')
	{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"tuvan", -1, -1, "and hoten like '%$tukhoa%' or cauhoi like '%$tukhoa%'",'');
	}
}
?>